package com.ruoyi.web.controller.common;

import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.ImmutableList;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ruoyi.web.controller.common.RobotConstant.ROBOT_NAME;
import static com.ruoyi.web.controller.common.RobotConstant.SEND_ROBOT_URL;
import static com.ruoyi.web.controller.common.RobotFeatureEnum.DUJITANG;
import static com.ruoyi.web.controller.common.RobotFeatureEnum.ZAOAN;

@Service
@Slf4j
public class RobotJob {

    List<String> TO_ROOM = ImmutableList.of(
        "19168435512@chatroom",
        "9515223784@chatroom"
    );

    @Scheduled(cron = "0 20 9 ? * 1-5")
    public void test() {
        for (String s : TO_ROOM) {
            StringBuilder sb = new StringBuilder();
            sb.append(ROBOT_NAME + "提醒您，现在是北京时间" + DateUtil.now() + "，赌场还有10分钟就要开门了，请做好准备！上次赌场信息，请查收:");
            sb.append(ApiUtil.getZhiShuInfo());
            sb.append("\n");
            sb.append("早，");
            sb.append(ApiUtil.getSimpleTalk(ZAOAN));
            Map<String, Object> map = new HashMap<>();
            map.put("success", Boolean.TRUE);
            map.put("robot_wxid", "wxid_shhrqqr93hib22");
            map.put("to_wxid", s);
            map.put("group_wxid", s);
            map.put("event", "SendTextMsg");
            map.put("msg", sb.toString());
            String s1 = JSON.toJSONString(map, SerializerFeature.BrowserCompatible);
            HttpRequest.post(SEND_ROBOT_URL)
                .header("Content-type", "application/json;charset=utf-8")
                .body(s1)
                .timeout(20000)
                .execute().body();
            System.out.println("\"hhhh\" = " + "hhhah");
        }
    }

    @Scheduled(cron = "0 50 14 ? * 1-5")
    public void test2() {
        for (String s : TO_ROOM) {
            StringBuilder sb = new StringBuilder();
            sb.append(ROBOT_NAME + "提醒您，现在是北京时间" + DateUtil.now() + "，赌场还有10分钟就要关门了，请做好准备！今天赌场信息，请查收:");
            sb.append("\n");
            sb.append(ApiUtil.getZhiShuInfo());
            sb.append("\n");
            sb.append(ROBOT_NAME + "鸡汤：");
            sb.append(ApiUtil.getSimpleTalk(DUJITANG));
            Map<String, Object> map = new HashMap<>();
            map.put("success", Boolean.TRUE);
            map.put("robot_wxid", "wxid_shhrqqr93hib22");
            map.put("to_wxid", s);
            map.put("group_wxid", s);
            map.put("event", "SendTextMsg");
            map.put("msg", sb.toString());
            String s1 = JSON.toJSONString(map, SerializerFeature.BrowserCompatible);
            HttpRequest.post(SEND_ROBOT_URL)
                .header("Content-type", "application/json;charset=utf-8")
                .body(s1)
                .timeout(20000)
                .execute().body();
            System.out.println("\"hhhh\" = " + "hhhh");
        }
    }

    @Scheduled(cron = "0 05 8 ? * 1-5")
    public void test3() {
        for (String s : TO_ROOM) {
            StringBuilder sb = new StringBuilder();
            sb.append(ROBOT_NAME + "提醒您，现在是北京时间" + DateUtil.now() + "，赌场还有10分钟就要关门了，请做好准备！今天赌场信息，请查收:");
            sb.append("\n");
            sb.append(ApiUtil.getZhiShuInfo());
            sb.append("\n");
            sb.append(ROBOT_NAME + "鸡汤：");
            sb.append(ApiUtil.getSimpleTalk(DUJITANG));
            Map<String, Object> map = new HashMap<>();
            map.put("success", Boolean.TRUE);
            map.put("robot_wxid", "wxid_shhrqqr93hib22");
            map.put("to_wxid", "23712025745@chatroom");
            map.put("group_wxid", "23712025745@chatroom");
            map.put("event", "SendTextMsg");
            map.put("msg", "sss");
            String s1 = JSON.toJSONString(map, SerializerFeature.BrowserCompatible);
            HttpRequest.post(SEND_ROBOT_URL)
                .header("Content-type", "application/json;charset=utf-8")
                .body(s1)
                .timeout(20000)
                .execute().body();
            System.out.println("\"hhhh\" = " + s);
        }
    }

    @Scheduled(cron = "0 */1 * * * ?")
    public void test4() {
        StringBuilder sb = new StringBuilder();
        sb.append(ROBOT_NAME + "提醒您，现在是北京时间" + DateUtil.now() + "，赌场还有10分钟就要关门了，请做好准备！今天赌场信息，请查收:");
        sb.append("\n");
        sb.append(ApiUtil.getZhiShuInfo());
        sb.append("\n");
        sb.append(ROBOT_NAME + "鸡汤：");
        sb.append(ApiUtil.getSimpleTalk(DUJITANG));
        Map<String, Object> map = new HashMap<>();
        map.put("success", Boolean.TRUE);
        map.put("robot_wxid", "wxid_shhrqqr93hib22");
        map.put("to_wxid", "47574067957@chatroom");
        map.put("group_wxid", "47574067957@chatroom");
        map.put("event", "SendTextMsg");
        map.put("msg", "sss");
        String s1 = JSON.toJSONString(map, SerializerFeature.BrowserCompatible);
        HttpRequest.post(SEND_ROBOT_URL)
            .header("Content-type", "application/json;charset=utf-8")
            .body(s1)
            .timeout(20000)
            .execute().body();
        log.error("sdfasdfasfa");
    }
}
